package com.gd.data.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gd.data.platform.entity.AlertRule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 告警规则Mapper
 * 操作MySQL中的告警规则数据
 * 
 * @author gd-data-platform
 * @since 1.0.0
 */
@Mapper
public interface AlertRuleMapper extends BaseMapper<AlertRule> {

    /**
     * 查询所有启用的告警规则
     */
    @Select("SELECT * FROM alert_rules WHERE enabled = true ORDER BY alert_level DESC, create_time DESC")
    List<AlertRule> findEnabledRules();

    /**
     * 根据指标类型查询告警规则
     */
    @Select("SELECT * FROM alert_rules WHERE metric_type = #{metricType} AND enabled = true")
    List<AlertRule> findByMetricType(@Param("metricType") String metricType);

    /**
     * 根据告警级别查询告警规则
     */
    @Select("SELECT * FROM alert_rules WHERE alert_level = #{alertLevel} AND enabled = true")
    List<AlertRule> findByAlertLevel(@Param("alertLevel") String alertLevel);

    /**
     * 根据创建者查询告警规则
     */
    @Select("SELECT * FROM alert_rules WHERE creator = #{creator} ORDER BY create_time DESC")
    List<AlertRule> findByCreator(@Param("creator") String creator);
}
